import { Button } from '@antmjs/vantui';
import { eventsBus, toast } from '@vh-mobile/pro-utils';
import { useEffect } from 'react';
import { CSpaceCustom } from '@vh-mobile/pro-components';
import MainContainerCustom from '@/components/MainContainerCustom';

export default function DemoEventsBus() {
  useEffect(() => {
    eventsBus.$on('eventsBus', (data: any) => {
      console.log(data);
      toast.show('触发');
    });
    return () => {
      eventsBus.$off('eventsBus');
    };
  }, []);

  const showModal = () => {
    eventsBus.$trigger('eventsBus', {
      content: '欢迎使用',
    });
  };
  const showIndexModal = () => {
    eventsBus.$trigger('indexEventsBus');
  };
  return (
    <MainContainerCustom>
      <CSpaceCustom direction="vertical" align="center">
        <Button onClick={showModal} block={true} type="primary">
          发送事件
        </Button>
        <Button onClick={showIndexModal} block={true} type="primary">
          发送首页事件
        </Button>
      </CSpaceCustom>
    </MainContainerCustom>
  );
}
